package nimy.info.android.dinnertime.page;

import nimy.info.android.dinnertime.R;
import android.content.Intent;

import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.ShareActionProvider;

public abstract class AbstractSinglePage extends SherlockFragment {

	private ShareActionProvider shareActionProvier;

	protected boolean inflaterShareAction(Menu menu, MenuInflater inflater) {
		MenuInflater menuInflater = inflater == null ? getSherlockActivity()
				.getSupportMenuInflater() : inflater;
		// Inflate your menu.
		menuInflater.inflate(R.menu.share_action_provider, menu);

		// Set file with share history to the provider and set the share intent.
		MenuItem actionItem = menu
				.findItem(R.id.menu_item_share_action_provider_action_bar);
		shareActionProvier = (ShareActionProvider) actionItem
				.getActionProvider();
		shareActionProvier
				.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
		// Note that you can set/change the intent any time,
		// say when the user has selected an image.
		// shareActionProvier.setShareIntent(createShareIntent());
		return true;
	}

	protected void setShareIntent(final Intent intent) {
		if (shareActionProvier != null && intent != null) {
			shareActionProvier.setShareIntent(intent);
		}
	}

	/**
	 * Creates a sharing {@link Intent}.
	 * 
	 * @return The sharing intent.
	 */
	protected Intent createShareIntent() {
		return null;
	}
}
